﻿@model BeYourMarket.Model.Models.MessageThread
@using Microsoft.AspNet.Identity

@{
    ViewBag.Title = "[[[Messages]]]";
}

<div class="body-content container-fluid">
    <div class="main-section row">
        <div class="container-fluid mrg-tb">

            @Html.Partial("_DashBoardSide", "messages")

            <div class=" col-md-9">
                <div id="myTabContent" class="tab-content">
                    <div role="tabpanel" class="tab-pane card-content fade active in" id="listings" aria-labelledby="listings-tab">
                        @Html.Partial("_UserMessage")

                        <div class="btn-toolbar" role="toolbar">
                            <div class="btn-group">
                                <a class="btn btn-sm btn-primary" href="@Url.Action("Messages", "Manage")" title="[[[Messages]]]"><i class="fa fa-fw fa-level-up fa-rotate-270"></i></a>
                            </div>
                        </div>

                        <!-- Message -->
                        <div class="panel panel-default m-t-20">

                            <!-- Header -->
                            <div class="panel-heading">
                                <h3 class="panel-title"><i class="fa fa-users"></i> @string.Join(", ", Model.MessageParticipants.Select(x => x.AspNetUser.FullName).ToArray())</h3>
                            </div>

                            <div class="panel-heading">
                                <h3 class="panel-title"><i class="fa fa-comments-o"></i> @Model.Subject</h3>
                            </div>
                            <!-- Header -->
                            <!-- Listing -->
                            @if (Model.ListingID.HasValue)
                            {
                                <div class="panel-body p-t-10 p-b-10">
                                    <div class="col-md-2">
                                        <a href="@Url.Action("Listing", "Listing", new { id = Model.ListingID })">
                                            <img class="thumb-lg img-circle" src="@BeYourMarket.Web.Utilities.ImageHelper.GetListingImagePath(Model.Listing.DefaultPictureID)" />
                                        </a>
                                    </div>

                                    <div class="col-md-10">
                                        <a href="@Url.Action("Listing", "Listing", new { id = Model.ListingID })">
                                            <h3>
                                                @Model.Listing.Title
                                                <span class="score @Model.Listing.RatingClass text-md"></span>
                                            </h3>
                                        </a>

                                        @if (Model.Listing.Price.HasValue)
                                        {
                                            <h4>
                                                @Html.DisplayFor(x => x.Listing.PriceFormatted) @Model.Listing.ListingType.PriceUnitLabel
                                            </h4>
                                        }
                                        <p class="lead text-lighten">
                                            @Model.Listing.Location
                                        </p>

                                    </div>
                                </div>
                            }
                            <!-- Listing -->
                            <!-- Reply -->
                            <div class="panel-body p-t-10 p-b-10">
                                <div class="media">
                                    <a href="@Url.Action("Profile", "Listing", new { id = User.Identity.GetUserId() })" class="pull-left">
                                        <img class="pull-left media-object img-circle thumb-sm" src="@BeYourMarket.Web.Utilities.ImageHelper.GetUserProfileImagePath(User.Identity.GetUserId())" />
                                    </a>
                                    <div class="media-body">
                                        <form action="@Url.Action("Message", "Manage")" method="post" role="form">
                                            <input type="hidden" name="threadId" id="threadId" value="@Model.ID" />
                                            <textarea class="form-control m-b-10" id="messageText" name="messageText" required rows="4" placeholder="[[[Reply here...]]]"></textarea>
                                            <button class="btn btn-primary" type="submit"><i class="fa fa-send"></i> [[[Send Message]]]</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <!-- Reply -->

                            <div class="panel-body">
                                <table class="table table-striped">
                                    <tbody>
                                        @foreach (var message in Model.Messages.OrderByDescending(x => x.Created))
                                        {
                                            <tr>
                                                <td class="col-md-2">
                                                    <div class="media">
                                                        <a href="@Url.Action("Profile", "Listing", new { id = message.AspNetUser.Id })" cla class="pull-left">
                                                            <img class="pull-left media-object img-circle thumb-sm" src="@BeYourMarket.Web.Utilities.ImageHelper.GetUserProfileImagePath(message.AspNetUser.Id)" />
                                                        </a>
                                                        <small class="text-muted">@message.AspNetUser.FullName</small>
                                                    </div> <!-- media -->
                                                </td>
                                                <td>
                                                    <div>
                                                        <p style="white-space: pre-line" class="text-sm">@Html.Raw(message.Body)</p>
                                                    </div>
                                                </td>
                                                <td class="col-md-2">
                                                    <span class="media-meta pull-right"><i class="fa fa-clock-o"></i> @(message.Created.Date == DateTime.Today.Date ? message.Created.ToShortTimeString() : message.Created.ToShortDateString())</span>
                                                </td>
                                            </tr>

                                        }
                                    </tbody>
                                </table>
                            </div>
                            <!-- panel-body -->

                        </div> <!-- End panel -->
                        <!-- End message -->

                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts {
}